/**
 * This file is part of Sonedyan.
 * 
 * Sonedyan is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation;
 * either version 3 of the License, or (at your option) any
 * later version.
 *
 * Sonedyan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Octave; see the file COPYING.  If not
 * see <http://www.gnu.org/licenses/>.
 * 
 * Copyright (C) 2009-2012 Jimmy Dubuisson <jimmy.dubuisson@gmail.com>
 */

package org.unige.mpej.eckmann.sonedyan.enron.bean;

import javax.mail.Address;
import javax.mail.internet.InternetAddress;

/**
 * Class representing an email
 */
public class Email 
{
	// ENRON1: martin.cuilla@enron.com, sandra.brawner@enron.com, sandra.f.brawner@enron.com,jim.derrick@enron.com,james_derrick@enron.com
	// ENRON2: mcuilla@enron.com, f..brawner@enron.com
	// ENRON3: mcuilla@ect.enron.com
	// NOT_ENRON_PRO: jdasovich@ubswenergy.com
	// PRIVATE: mcuilla@hotmail.com
	public enum Type { ENRON1, ENRON2, ENRON3, NOT_ENRON_PRO, PRIVATE }
	
	private Address address;
	
	// set manually 
	private Type type;
	
	/**
	 * default constructor
	 */
	public Email(){}
	
	/**
	 * check if the specified email is an enron email
	 */
	public static boolean isEnronEmail(String email)
	{
		if (email != null && email.endsWith("enron.com"))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * check if the specified email is an enron email
	 */
	public static boolean isEnronEmail(Address address)
	{
		if (address != null && address.toString().endsWith("enron.com"))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public Email(Address address)
	{
		this.address = address;
		this.type = null;
	}
	
	public Address getAddress()
	{
		return address;
	}

	public void setAddress(Address address)
	{
		this.address = address;
	}
	
	public void setAddress(String addressString)
	{
		try
		{
			this.address = new InternetAddress(addressString);
		}
		catch(Exception e){}
	}
	
	public Type getType()
	{
		return type;
	}

	public void setType(Type type)
	{
		this.type = type;
	}
		
}
